<template>
  <div class="card-container">
    <div class="more-info-box">
      <el-row class="more-info-row">
        <el-col :span="16"><el-text>工号: {{ userData.employeeId }} </el-text></el-col>
        <el-col :span="8"><el-text>所属学院: {{ userData.department }}</el-text></el-col>
      </el-row>
      <el-row class="more-info-row">
        <el-col :span="16"><el-text>职位: {{ userData.position }}</el-text></el-col>
        <el-col :span="8"><el-text>职级: {{ userData.title }}</el-text></el-col>
      </el-row>
      <el-row class="more-info-row">
        <el-col :span="16"><el-text>电话号码: {{ userData.phone }}</el-text></el-col>
        <el-col :span="8"><el-text>办公室: {{ userData.office }}</el-text></el-col>
      </el-row>
      <el-row class="more-info-row">
        <el-col :span="16"><el-text>入职日期: {{ userData.hireDate }}</el-text></el-col>
      </el-row>
    </div>

    <div class="fix-button">
      <el-button circle  @click="startSetting()" >
        <el-icon style="vertical-align: middle">
          <Setting />
        </el-icon>
      </el-button>
    </div>
  </div>

  <el-dialog class="dialog" v-model="dialogFormVisible" title="用户信息" width="500" :lock-scroll="false" >
    <el-form :model="formData" ref="formRef">
      <br/>
      <el-form-item label="姓名：" :label-width='100'>
        <el-input v-model="formData.name" autocomplete="off" style="width: 90%"/>
      </el-form-item>
      <el-form-item label="学院：" :label-width='100'>
        <el-input v-model="formData.department" autocomplete="off" style="width: 90%"/>
      </el-form-item>
      <el-form-item label="职级：" :label-width='100'>
        <el-input v-model="formData.title" autocomplete="off" style="width: 90%"/>
      </el-form-item>
      <el-form-item label="职位：" :label-width='100'>
        <el-input v-model="formData.position" autocomplete="off" style="width: 90%"/>
      </el-form-item>
      <el-form-item label="电话号码：" :label-width='100'>
        <el-input v-model="formData.phone" autocomplete="off" style="width: 90%"/>
      </el-form-item>
      <el-form-item label="办公室地址：" :label-width='100'>
        <el-input v-model="formData.office" autocomplete="off" style="width: 90%"/>
      </el-form-item>
      <el-form-item label="入职日期：" :label-width='100'>
        <el-date-picker
            v-model="formData.hireDate"
            type="date"
            aria-label="选择日期"
            :placeholder="formData.hireDate"
            style="width: 90%"
        />
      </el-form-item>
    </el-form>
    <!--提交和取消按钮-->
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import {defineProps, onMounted, reactive, ref} from 'vue';
import {Setting} from "@element-plus/icons-vue";
import {setUserById} from "@/api/userApi/userApi.js";
import {ElMessage, ElNotification} from "element-plus";

const props = defineProps({
  userData:{}
})

//------------------------提交表单标识物---------------------------------------
const dialogFormVisible = ref(false);

//------------------------设置信息处理函数---------------------------------------
function startSetting(){
  dialogFormVisible.value = true;
  formData.value = props.userData
}

//表单数据
const formData = ref({})

//表单ref
const formRef = ref(null)

//提交函数
const submit = () => {
  setUserById(formData.value).then((res) => {
    if(res.status === 200){
      ElNotification.success({
        title: '修改成功',
        message: "用户数据已修改",
        type: 'warning',
      })
    }
  }).catch(() =>{
    ElMessage.error("修改失败")
  })
}
</script>

<style scoped>
.card-container{
  width: 100%;
  height: 50vh;
}
.more-info-box{
  width: 100%;
  margin-left: 6%;
  margin-right: 6%;
}
.more-info-row{
  width: 100%;
  margin-top: 20px;
  font-size: 30px;
  font-weight: bold;
}
.fix-button{
  margin-top: 5vh;
  width: 100%;
  display: flex;
  justify-content:  center;
}
</style>
